package models

import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type ApprovalSelfDefine struct{
	gorm.Model
	Name string
	StepLocalID string
	StepNo int64
	ApprovalID string
	CompanyID string
	IdentityID string
	Action string
	DoneTime time.Time
	IsDone bool
	DeviceInfo string
 }

func (table *ApprovalSelfDefine) TableName() string {

	return "approval_self_basic"
}

func GetApprovalSelfDefineList() []*ApprovalSelfDefine { 
	data := make([]*ApprovalSelfDefine,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindApprovalSelfDefineByName(name string) ApprovalSelfDefine {
	user := ApprovalSelfDefine{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindApprovalSelfDefineByID(id uint) ApprovalSelfDefine {
	user := ApprovalSelfDefine{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func CreateApprovalSelfDefine(user ApprovalSelfDefine) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func FindApprovalSelfDefineByStepID(id string,CompanyID string) []*ApprovalSelfDefine {
	user := make([]*ApprovalSelfDefine,100)
	utils.DB.Where("approval_id = ? and company_id = ?",id,CompanyID).Find(&user)
	return user
}

func FindApprovalSelfDefineByIDAndCompanyID(id uint,CompanyID string) ApprovalSelfDefine {
	user := ApprovalSelfDefine{}
	utils.DB.Where("id = ? and company_id = ?",id,CompanyID).First(&user)
	return user
}

func DeleteApprovalSelfDefine(user ApprovalSelfDefine) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateApprovalSelfDefine(user ApprovalSelfDefine) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(ApprovalSelfDefine{Name: user.Name, IdentityID: user.IdentityID, DeviceInfo: user.DeviceInfo})
}